#!/usr/bin/python
# -*- coding: utf-8 -*-
#Author: Onur ASLAN
#Mail : hata.pindir@gmail.com 


from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4.phonon import Phonon
from PyQt4 import phonon
from Ui_MainWindow import Ui_MainWindow
from urlparse import urlparse, parse_qs
from email.mime.text import MIMEText

import reportLock
import windowEffect
import watchOnlineVideo
import reportSend
import installPindir
import versionControl
import uninstallPindir
import saveSettings
import findVideoImage
import subprocess

import threading, thread
import getpass, urllib2, urllib
import sys
import os
import icons_rc
import shutil
import tarfile
import smtplib

# example url http://www.youtube.com/watch?v=4o29VoxtsFk

try:
    import gdata.youtube, gdata.youtube.service 
    
except:
    print u"""'gdata-python-client' yüklü olması lazım. Lütfen yükleyip tekrar deneyiniz.\n <python-gdata> <sudo pisi it python-gdata> http://code.google.com/p/gdata-python-client/downloads/"""
    sys.exit()


		
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
	def __init__(self):
		QtGui.QMainWindow.__init__(self)
		self.setupUi(self)
		self.radioButton.setChecked(True)
		#self.lineEdit.setEchoMode(QtGui.QLineEdit.NoEcho)
		self.video_onizle.setScaledContents(True)
		self.textBrowser.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
		self._ac2 = QtGui.QPushButton(self.frame_2)
		self._ac2.setGeometry(QtCore.QRect(280, 180, 111, 27))
		icon27 = QtGui.QIcon()
		icon27.addPixmap(QtGui.QPixmap("../../../../../usr/share/icons/milky/32x32/actions/dialog-ok-apply.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self._ac2.setIcon(icon27)
		self._ac2.setIconSize(QtCore.QSize(15, 15))
		self._ac2.setFlat(True)
		self._ac2.setObjectName("_ac2")
		
		global dil, aa, convert_file, convert_new_file, name_user
		
					
                aa = str(self.ayar_yol.text())                                                          
                convert_file = str(self.dosya_ac.text())
                convert_new_file = str(self.lineEdit_3.text())    
                name_user = getpass.getuser()
                		
 		dosyaa = open("/home/"+str(getpass.getuser())+"/.pindir_ayar.txt")
 		for satir in dosyaa:
	  		dil = satir
	  	dosyaa.readline()
	  			
               	if dil =="Türkçe": 
                		self._ac2.setText(unicode("Geliştirici"))
		if dil == "English":
				self._ac2.setText("Developer")

	
		
		QtCore.QObject.connect(self.all_send_trash, QtCore.SIGNAL("clicked()"), self.removeFiles)
		QtCore.QObject.connect(self.send_trash, QtCore.SIGNAL("clicked()"), self.removeFile)      
		QtCore.QObject.connect(self.listWidget, QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.videoPlayerLoad)
		QtCore.QObject.connect(self.play, QtCore.SIGNAL("clicked()"), self.videoPlayer.play)
		QtCore.QObject.connect(self.pushButton_3, QtCore.SIGNAL("clicked()"), self.videoPlayer.pause)		
		QtCore.QObject.connect(self.izle, QtCore.SIGNAL("clicked()"), self.izleee)	
	        QtCore.QObject.connect(self.pushButton_9, QtCore.SIGNAL("clicked()"), self.kapat)
	        QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL("clicked()"), self.kapat)
   		QtCore.QObject.connect(self.pushButton_7, QtCore.SIGNAL("clicked()"), self.ayar_iptal)   		
   		QtCore.QObject.connect(self.ayar_tamam, QtCore.SIGNAL("clicked()"), self.saveSetting)     		  
       		QtCore.QObject.connect(self.pushButton_10, QtCore.SIGNAL("clicked()"), self.dosya_ac.clear)
                QtCore.QObject.connect(self.pushButton_10, QtCore.SIGNAL("clicked()"), self.lineEdit_3.clear)
                QtCore.QObject.connect(self.pushButton_10, QtCore.SIGNAL("clicked()"), self.pushButton_8.show)
                QtCore.QObject.connect(self.pushButton_10, QtCore.SIGNAL("clicked()"), self.label_8.clear)
                QtCore.QObject.connect(self.pushButton_12, QtCore.SIGNAL("clicked()"), self.pushButton_8.show)  
                QtCore.QObject.connect(self.ayar_dizin, QtCore.SIGNAL("clicked()"), self.dizingoster)  
                QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL("clicked()"), self.getVideoImage)  
                QtCore.QObject.connect(self.pushButton_13, QtCore.SIGNAL("clicked()"), self.versionOnlineControl)
                QtCore.QObject.connect(self.kilit_sifre, QtCore.SIGNAL("clicked()"), self.durumgizle)
                QtCore.QObject.connect(self.kilit_ac, QtCore.SIGNAL("clicked()"), self.openLock)                                        
   		QtCore.QObject.connect(self.pushButton_11, QtCore.SIGNAL("clicked()"), self.writeReport)
   		QtCore.QObject.connect(self.pushButton_8, QtCore.SIGNAL("clicked()"), self.settingsWindowEffect)
   		QtCore.QObject.connect(self.pushButton_7, QtCore.SIGNAL("clicked()"), self.settingsWindowEffectClose)
                QtCore.QObject.connect(self._ac2, QtCore.SIGNAL("clicked()"), self.loginAdmin) 
                QtCore.QObject.connect(self.pushButton_12, QtCore.SIGNAL("clicked()"), self.watchVideoEffectClose) 
                QtCore.QObject.connect(self.izle, QtCore.SIGNAL("clicked()"), self.watchVideoEffect)  
                QtCore.QObject.connect(self.indir_kur_2, QtCore.SIGNAL("clicked()"), self.nowInstall)
                QtCore.QObject.connect(self.pushButton_16, QtCore.SIGNAL("clicked()"), self.versionEffect)
		QtCore.QObject.connect(self.pindirkaldir2, QtCore.SIGNAL("clicked()"), self.nowUninstallPindir)
		QtCore.QObject.connect(self.pindirkaldir, QtCore.SIGNAL("clicked()"), self.kaldirmayigoster)	
		QtCore.QObject.connect(self.pindirkaldirvazgec, QtCore.SIGNAL("clicked()"), self.frame_kaldirma.hide)
                QtCore.QObject.connect(self.indir_pncr_kapat, QtCore.SIGNAL("clicked()"), self.nowInstallClose)
		QtCore.QObject.connect(self.pushButton_yol, QtCore.SIGNAL("clicked()"), self.findFile)
		QtCore.QObject.connect(self.getRootPassOk, QtCore.SIGNAL("clicked()"), self.nowInstallTwo)
		QtCore.QObject.connect(self.getRootPassUnins, QtCore.SIGNAL("clicked()"), self.nowUninstallPindirTwo)
						
	def nowInstall(self):	

		if dil == "Türkçe":
			self.indir_kur_durum.setText(unicode("Dosyaların yüklenmesi için\n parolanızı yazınız."))  
		if dil == "English":
			self.indir_kur_durum.setText(unicode("Please write password."))	
			
		self.indir_kur_2.hide()
		self.getRootPass.show()
        	self.getRootPassOk.show()	
		
		
	def nowInstallTwo(self):	
		installPindir.install(self)
		
	def saveSetting(self):	
		saveSettings.applySettings(self)		
			
	def settingsWindowEffect(self):
		windowEffect.effectSettings(self)
		
	def settingsWindowEffectClose(self):
		windowEffect.effectSettingsClose(self)	

	def watchVideoEffect(self):
		windowEffect.effectWatch(self)
		
	def watchVideoEffectClose(self):
		windowEffect.effectWatchClose(self)

	def versionEffect(self):
		windowEffect.effectVersion(self)
	
	def nowInstallClose(self):	
		windowEffect.effectAutoInstall(self)
					
	def writeReport(self):
		reportSend.send(self)	

 	def versionOnlineControl(self):
 		versionControl.control(self)
              	  			  	  	
   	def getVideoImage(self):
   		pass
   		#findVideoImage.getImageHQ(self)        
         	        	
         	
    	def loginAdmin(self):
    		reportLock.adminLock(self)
    					
   	def openLock(self):	
		reportLock.userLock(self)   

  	def nowUninstallPindirTwo(self):
   		self.getRootPassUnins.hide()
  		self.getRootPassLine.hide() 		
		uninstallPindir.uninstall(self)
		self.bilgiver.show()
		
		
  	def nowUninstallPindir(self):	
  		self.getRootPassUnins.show()
  		self.getRootPassLine.show()


	def kaldirmayigoster(self):
		self.frame_kaldirma.show()
		
	def izleee(self):
		watchOnlineVideo.watchVideo(self)
	
   	def ayar_iptal(self): 
   		oldAddress = unicode(self.labelSettingsAddress.text())
        	self.ayar_yol.setText(oldAddress)
  
        def findFile(self):     
                konum = QtGui.QFileDialog.getOpenFileName(self, u"Dosya Seç", "", u"*.mp3 *.ogg *.wma *.wav *.mkv *.mp4 *.avi *3gp *.mpg *.wmv *.flv (*.mp3 *.ogg *.wma *.wav *.mkv *.mp4 *.avi *3gp *.mpg *.wmv *.flv)")
                if len(konum) > 0:
                    self.dosya_ac.setText(str(konum))  
        	        
	def kapat(self):        
		sys.exit()
			
	def durumgizle(self):
		sifre = self.kilit_sifre.text()
		if sifre == "":
			self.kilit_durum.hide()			
 	
 	def dizingoster(self):
		konum = QtGui.QFileDialog.getExistingDirectory()
		self.ayar_yol.setText(unicode(konum))
		
	def removeFile(self):
		#url = unicode(self.listWidget.currentItem().text())
		#os.remove(url)
		self.items = self.listWidget.selectedItems()

		if self.items is not None:
		    for item in self.items:
			self.listWidget.takeItem(self.listWidget.row(item))

	def removeFiles(self):
		self.listWidget.clear()
		
	def videoPlayerLoad(self):
		url = unicode(self.listWidget.currentItem().text())
		self.videoPlayer.load(Phonon.MediaSource(url))
		self.videoPlayer.play()		
			
	@QtCore.pyqtSignature("bool")
	def on_btn_about_clicked(self):

		self.tabWidget.setCurrentIndex(4)	
		self.widget_3.show()
		self.animate = QtCore.QPropertyAnimation (self.widget_3, "geometry")
		self.animate.setDuration (400)
		self.animate.setStartValue(QtCore.QRect (-250, 9, 763, 363))
		self.animate.setEndValue(QtCore.QRect (4, 9, 763, 363))
		self.animate.start()


	@QtCore.pyqtSignature("bool")
	def on_indir_kur_clicked(self):
		self.indir_kur_2.setEnabled(True)
		self.widget_8.show()
		self.animate = QtCore.QPropertyAnimation (self.widget_8, "geometry")
		self.animate.setDuration (700)
		self.animate.setStartValue(QtCore.QRect (-10, 80, 371, 181))
		self.animate.setEndValue(QtCore.QRect (220, 80, 371, 181))
		self.animate.start()  
			

   		self.indir_kur_2.setEnabled(True)

		if dil == "Türkçe":
			self.indir_kur_durum.setText(unicode("Arşiv İndirildi Şimdi Kur?"))  
		if dil == "English":
			self.indir_kur_durum.setText(unicode("Archive Downloaded. Now İnstall?"))
 		  		
                site = urllib.urlopen("http://pindir.googlecode.com/svn/wiki/Version.wiki")
                version = site.read()  	
		targz = urllib2.urlopen("http://pindir.googlecode.com/files/"+"Pindir-"+str(version)+".tar.gz")
		eveindir = open("/home/"+getpass.getuser()+"/"+"Pindir-"+str(version)+".tar.gz", "w")
		eveindir.write(targz.read())
		targz.close()
					
		tar = tarfile.open("/home/"+getpass.getuser()+"/"+"Pindir-"+str(version)+".tar.gz")		
		dosya = tar.extractall("/home/"+getpass.getuser())
		dosya.read()	
		d = open("/home/"+getpass.getuser(), "w")
		d.write(dosya.read())
		d.close()		
		
 
		
        @QtCore.pyqtSignature("bool")
        def on_cevir3gp_clicked(self):  
		global dil, aa, convert_file, convert_new_file, name_user
							
                aa = str(self.ayar_yol.text())                                                          
                convert_file = str(self.dosya_ac.text())
                convert_new_file = str(self.lineEdit_3.text())    
                name_user = getpass.getuser()
                		
 		dosyaa = open("/home/"+str(getpass.getuser())+"/.pindir_ayar.txt")
 		for satir in dosyaa:
	  		dil = satir       
	  		             
                self.widget_5.show()             
                if dil == "Türkçe":
                        self.label_8.setText(unicode("'3gp' Formatlanıyor"))
                if dil == "English":
                        self.label_8.setText(unicode("Converting to '3gp'"))
                self.video_onizle.setPixmap(QtGui.QPixmap(":/icons/convrt-3gp.png"))
                thread.start_new_thread(self.convert_3gp, ())
                        
        def convert_3gp(self):
                new_file = str(self.ayar_yol.text())+"/"+convert_new_file+".3gp"                
                liste = self.listWidget
                liste.addItem(new_file )   
                      
          
                if(self.radioButton.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s qcif -vcodec h263 -acodec aac -ac 1 -ar 8000 -r 25 -ab 32 -y "+aa+"/'"+convert_new_file+"'"+".3gp") 
                if(self.radioButton_5.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s qcif -vcodec h263 -acodec aac -ac 1 -ar 8000 -r 25 -ab 32 -y "+"-s 800x600 "+aa+"/'"+convert_new_file+"'"+".3gp")
                if(self.radioButton_3.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s qcif -vcodec h263 -acodec aac -ac 1 -ar 8000 -r 25 -ab 32 -y "+"-s 352x288 "+aa+"/'"+convert_new_file+"'"+".3gp")  
                if(self.radioButton_2.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s qcif -vcodec h263 -acodec aac -ac 1 -ar 8000 -r 25 -ab 32 -y "+"-s 320x240 "+aa+"/'"+convert_new_file+"'"+".3gp")
                if(self.radioButton_4.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s qcif -vcodec h263 -acodec aac -ac 1 -ar 8000 -r 25 -ab 32 -y "+"-s 640x480 "+aa+"/'"+convert_new_file+"'"+".3gp")
                if(self.radioButton_6.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s qcif -vcodec h263 -acodec aac -ac 1 -ar 8000 -r 25 -ab 32 -y "+"-s 1024x768 "+aa+"/'"+convert_new_file+"'"+"..3gp")                
                self.widget_5.hide()


                
                                
                
        @QtCore.pyqtSignature("bool")
        def on_ceviravi_clicked(self):  
        	global dil, aa, convert_file, convert_new_file, name_user
							
                aa = str(self.ayar_yol.text())                                                          
                convert_file = str(self.dosya_ac.text())
                convert_new_file = str(self.lineEdit_3.text())    
                name_user = getpass.getuser()     
                
                
                self.video_onizle.setPixmap(QtGui.QPixmap(":/icons/convrt-avi.png"))
                self.widget_5.show()
                if dil == "Türkçe":
                        self.label_8.setText(unicode("'avi' Formatlanıyor"))
                if dil == "English":
                        self.label_8.setText(unicode("Converting to 'avi'"))
                thread.start_new_thread(self.convert_avi, ()) 
                                  
        def convert_avi(self):
                new_file = str(self.ayar_yol.text())+"/"+convert_new_file+".avi"               
                liste = self.listWidget
                liste.addItem(new_file) 
                        
                if(self.radioButton.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"'"+aa+"/"+convert_new_file+"'"+".avi")      
                if(self.radioButton_5.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 800x600 "+"'"+aa+"/"+convert_new_file+"'"+".avi")
                if(self.radioButton_3.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 352x288 "+"'"+aa+"/"+convert_new_file+"'"+".avi")       
                if(self.radioButton_2.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 320x240 "+"'"+aa+"/"+convert_new_file+"'"+".avi")
                if(self.radioButton_4.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 640x480 "+"'"+aa+"/"+convert_new_file+"'"+".avi")
                if(self.radioButton_6.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 1024x768 "+"'"+aa+"/"+convert_new_file+"'"+".avi")              
                
                self.widget_5.hide()    
                
                
                
                
                                
        @QtCore.pyqtSignature("bool")
        def on_cevirmp4_clicked(self):
        
		global dil, aa, convert_file, convert_new_file, name_user
							
                aa = str(self.ayar_yol.text())                                                          
                convert_file = str(self.dosya_ac.text())
                convert_new_file = str(self.lineEdit_3.text())    
                name_user = getpass.getuser()        
                self.video_onizle.setPixmap(QtGui.QPixmap(":/icons/convrt-mp4.png"))
                self.widget_5.show()
                if dil == "Türkçe":
                        self.label_8.setText(unicode("'mp4' Formatlanıyor"))
                if dil == "English":
                        self.label_8.setText(unicode("Converting to 'mp4'"))
                thread.start_new_thread(self.convert_mp4, ()) 
                                  
        def convert_mp4(self):
                new_file = str(self.ayar_yol.text())+"/"+convert_new_file+".mp4"               
                liste = self.listWidget
                liste.addItem(new_file)
                                        
                if(self.radioButton.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"'"+aa+"/"+convert_new_file+"'"+".mp4")      
                if(self.radioButton_5.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 800x600 "+"'"+aa+"/"+convert_new_file+"'"+".mp4")
                if(self.radioButton_3.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 352x288 "+"'"+aa+"/"+convert_new_file+"'"+".mp4")   
                if(self.radioButton_2.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 320x240 "+"'"+aa+"/"+convert_new_file+"'"+".mp4")
                if(self.radioButton_4.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 640x480 "+"'"+aa+"/"+convert_new_file+"'"+".mp4")
                if(self.radioButton_6.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"++" -s 1024x768 "+"'"+aa+"/"+convert_new_file+"'"+".mp4")         
                self.widget_5.hide()
                        
                
                                
                
        @QtCore.pyqtSignature("bool")
        def on_cevirwav_clicked(self):
		global dil, aa, convert_file, convert_new_file, name_user
							
                aa = str(self.ayar_yol.text())                                                          
                convert_file = str(self.dosya_ac.text())
                convert_new_file = str(self.lineEdit_3.text())    
                name_user = getpass.getuser()           
                self.video_onizle.setPixmap(QtGui.QPixmap(":/icons/convrt-wav.png"))
                self.widget_5.show()
                if dil == "Türkçe":
                        self.label_8.setText(unicode("'wav' Formatlanıyor"))
                if dil == "English":
                        self.label_8.setText(unicode("Converting to 'wav'"))
                thread.start_new_thread(self.convert_wav, ())        
                           
        def convert_wav(self):
                new_file = str(self.ayar_yol.text())+"/"+convert_new_file+".wav"               
                liste = self.listWidget
                liste.addItem(new_file)          
                if(self.radioButton.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"'"+aa+"/"+convert_new_file+"'"+".wav")      
                if(self.radioButton_5.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 800x600 "+"'"+aa+"/"+convert_new_file+"'"+".wav")
                if(self.radioButton_3.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 352x288 "+"'"+aa+"/"+convert_new_file+"'"+".wav")   
                if(self.radioButton_2.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 320x240 "+"'"+aa+"/"+convert_new_file+"'"+".wav")
                if(self.radioButton_4.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 640x480 "+"'"+aa+"/"+convert_new_file+"'"+".wav")
                if(self.radioButton_6.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" -s 1024x768 "+"'"+aa+"/"+convert_new_file+"'"+".wav")
                
                self.widget_5.hide()    
   
                

                
                
                
        @QtCore.pyqtSignature("bool")
        def on_cevirwmv_clicked(self):
		global dil, aa, convert_file, convert_new_file, name_user
							
                aa = str(self.ayar_yol.text())                                                          
                convert_file = str(self.dosya_ac.text())
                convert_new_file = str(self.lineEdit_3.text())    
                name_user = getpass.getuser()  
                self.video_onizle.setPixmap(QtGui.QPixmap(":/icons/convrt-wmv.png"))
                self.widget_5.show()
                if dil == "Türkçe":
                        self.label_8.setText(unicode("'wmv' Formatlanıyor"))
                if dil == "English":
                        self.label_8.setText(unicode("Converting to 'wmv'"))
                thread.start_new_thread(self.convert_wmv, ())           
        def convert_wmv(self):
                new_file = str(self.ayar_yol.text())+"/"+convert_new_file+".wmv"
                liste = self.listWidget
                liste.addItem(new_file)
                                   
                if(self.radioButton.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"'"+aa+"/"+convert_new_file+"'"+".wmv")      
                if(self.radioButton_5.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 800x600 "+"'"+aa+"/"+convert_new_file+"'"+".wmv")
                if(self.radioButton_3.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 352x288 "+"'"+aa+"/"+convert_new_file+"'"+".wmv")       
                if(self.radioButton_2.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 320x240 "+"'"+aa+"/"+convert_new_file+"'"+".wmv")
                if(self.radioButton_4.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 640x480 "+"'"+aa+"/"+convert_new_file+"'"+".wmv")
                if(self.radioButton_6.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+" -s 1024x768 "+"'"+aa+"/"+convert_new_file+"'"+".wmv")
                
                self.widget_5.hide()

                
        @QtCore.pyqtSignature("bool")
        def on_cevirmp3_clicked(self):
		global dil, aa, convert_file, convert_new_file, name_user
							
                aa = str(self.ayar_yol.text())                                                          
                convert_file = str(self.dosya_ac.text())
                convert_new_file = str(self.lineEdit_3.text())    
                name_user = getpass.getuser() 
                self.video_onizle.setPixmap(QtGui.QPixmap(":/icons/convrt-mp3.png"))
                self.widget_5.show()
 
                if dil == "Türkçe":
                        self.label_8.setText(unicode("'mp3' Formatlanıyor"))
                if dil == "English":
                        self.label_8.setText(unicode("Converting to 'mp3'"))
                        
                thread.start_new_thread(self.convert_mp3, ())                   
        def convert_mp3(self):  
                new_file = str(self.ayar_yol.text())+"/"+convert_new_file+".mp3"
                liste = self.listWidget
                liste.addItem(new_file)                
                os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"'"+aa+"/"+convert_new_file+"'"+".mp3")      
                self.widget_5.hide()


                
                
        @QtCore.pyqtSignature("bool")
        def on_cevirmpg_clicked(self):
		global dil, aa, convert_file, convert_new_file, name_user
							
                aa = str(self.ayar_yol.text())                                                          
                convert_file = str(self.dosya_ac.text())
                convert_new_file = str(self.lineEdit_3.text())    
                name_user = getpass.getuser()
                self.video_onizle.setPixmap(QtGui.QPixmap(":/icons/convrt-mpg.png"))
                self.widget_5.show()


                if dil == "Türkçe":
                        self.label_8.setText(unicode("'mpg' Formatlanıyor"))
                if dil == "English":
                        self.label_8.setText(unicode("Converting to 'mpg'"))
                thread.start_new_thread(self.convert_mpg, ())
                                        
        def convert_mpg(self):
                
                liste = self.listWidget
                new_file = str(self.ayar_yol.text())+"/"+convert_new_file+".mp3"
                liste.addItem(new_file)                 
                        
                if(self.radioButton.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"-ab 56 -ar 22050 -b 500 "+"'"+aa+"/"+convert_new_file+"'"+".mpg")   
                if(self.radioButton_5.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"-ab 56 -ar 22050 -b 500"+" -s 800x600 "+"'"+aa+"/"+convert_new_file+"'"+".mpg")
                if(self.radioButton_3.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"-ab 56 -ar 22050 -b 500"+" -s 352x288 "+"'"+aa+"/"+convert_new_file+"'"+".mpg")     
                if(self.radioButton_2.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"-ab 56 -ar 22050 -b 500"+" -s 320x240 "+"'"+aa+"/"+convert_new_file+"'"+".mpg")
                if(self.radioButton_4.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"-ab 56 -ar 22050 -b 500"+" -s 640x480 "+"'"+aa+"/"+convert_new_file+"'"+".mpg")
                if(self.radioButton_6.isChecked() == True):
                        os.system("ffmpeg -i"+" "+"'"+convert_file+"'"+" "+"-ab 56 -ar 22050 -b 500"+" -s 1024x768 "+"'"+aa+"/"+convert_new_file+"'"+".mpg")
                        
                self.widget_5.hide()  
				
		

	@QtCore.pyqtSignature("bool")
	def on_aviindir_clicked(self):
		self.video_onizle.show()
	  		
		name = str(self.lineEdit_2.text())
		liste = self.listWidget

		isim = str(self.ayar_yol.text()+"/"+name+".avi")
		liste.addItem(isim)   	  		
	  	findVideoImage.getImageHQ(self)		

		self.widget_5.show()
		if dil == "Türkçe":
			self.label_8.setText(unicode("Adresten İndiriliyor"))
		if dil == "English":
			self.label_8.setText(unicode("Video Downloading"))

		thread.start_new_thread(self.indir5, ())

	def indir5(self):
		url = str(self.lineEdit.text())
		name = str(self.lineEdit_2.text())
		aa = str(self.ayar_yol.text())
 	
		print "Video Downloading"
		os.system("youtube-dl"+" "+"--output="+aa+"/'"+name+"'"+" "+url)		
		print name+".flv --> "+name+".avi"
		os.system("ffmpeg -i"+" "+aa+"/'"+name+"' "+aa+"/"+name+".avi")

		print "Video is converted"
		if dil == "Türkçe":
			self.label_8.setText(unicode("İndirme İşlemi Bitti"))
		if dil == "English":
			self.label_8.setText(unicode("Video Downloaded"))
			
		self.downVideoDescriptiont.clear()
		self.downVideoTitle.clear()
		self.downVideoViewCount.clear()
								
	@QtCore.pyqtSignature("bool")
	def on_mp4indir_clicked(self):
	
 		
		liste = self.listWidget
		name = str(self.lineEdit_2.text())
		isim = str(self.ayar_yol.text()+"/"+name+".mp4")
		liste.addItem(isim) 
		findVideoImage.getImageHQ(self)				
		self.video_onizle.show()
		self.widget_5.show()
		if dil == "Türkçe":
			self.label_8.setText(unicode("Adresten İndiriliyor"))
		if dil == "English":
			self.label_8.setText(unicode("Video Downloading"))
		thread.start_new_thread(self.indir4, ())
	
	def indir4(self):
		url = str(self.lineEdit.text())
		name = str(self.lineEdit_2.text())
		aa = str(self.ayar_yol.text())

		print "Video Downloading"
		os.system("youtube-dl"+" "+"--output="+aa+"/'"+name+"'"+" "+url)		
		print name+".flv --> "+name+".mp4"
		os.system("ffmpeg -i"+" "+aa+"/'"+name+"' "+aa+"/"+name+".mp4")

		print "Video is converted"
		if dil == "Türkçe":
			self.label_8.setText(unicode("İndirme İşlemi Bitti"))
		if dil == "English":
			self.label_8.setText(unicode("Video Downloaded"))
		self.downVideoDescriptiont.clear()
		self.downVideoTitle.clear()
		self.downVideoViewCount.clear()

		
	@QtCore.pyqtSignature("bool")
	def on_mp3indir_clicked(self):
		self.video_onizle.show()		

 		findVideoImage.getImageHQ(self)	
		liste = self.listWidget
		name = str(self.lineEdit_2.text())

		liste.addItem(str(self.ayar_yol.text()+"/"+name+".mp3"))  		
 			
		self.widget_5.show()
		if dil == "Türkçe":
			self.label_8.setText(unicode("Adresten İndiriliyor"))
		if dil == "English":
			self.label_8.setText(unicode("Video Downloading"))
		thread.start_new_thread(self.indir3, ())

	def indir3(self):
		url = str(self.lineEdit.text())
		name = str(self.lineEdit_2.text())

		aa = str(self.ayar_yol.text())
		print "Video Downloading"
		os.system("youtube-dl"+" "+"--output="+aa+"/'"+name+"'"+" "+url)		
		print ".flv --> .mp3"
		os.system("ffmpeg -i"+" "+aa+"/'"+name+"' "+aa+"/"+name+".mp3")
		
		print "Video is converted"
		if dil == "Türkçe":
			self.label_8.setText(unicode("İndirme İşlemi Bitti"))
		if dil == "English":
			self.label_8.setText(unicode("Video Downloaded"))	
		
		self.downVideoDescriptiont.clear()
		self.downVideoTitle.clear()
		self.downVideoViewCount.clear()		
		
	@QtCore.pyqtSignature("bool")
	def on_flvindir_clicked(self):
		self.video_onizle.show()
		self.widget_5.show()
	
		name = str(self.lineEdit_2.text())+".flv"		
		n_file = str(aa+"/"+name)
		liste = self.listWidget
		liste.addItem(n_file) 	
		
		findVideoImage.getImageHQ(self)		
			
		if dil == "Türkçe":
			self.label_8.setText(unicode("Adresten İndiriliyor"))
		if dil == "English":
			self.label_8.setText(unicode("Video Downloading"))
		thread.start_new_thread(self.indir, ())
				
	def indir(self):	
		url = str(self.lineEdit.text())
		name = str(self.lineEdit_2.text())+".flv"	
		print "Video Downloading"			
		n_file = str(aa+"/"+name)
		
		os.system("youtube-dl"+" "+"--output="+aa+"/'"+name+"'"+" "+url)
		
		self.widget_5.show()		
		print "Download Complete"
 		if dil == "Türkçe":
			self.label_8.setText(unicode("İndirme İşlemi Bitti"))
		if dil == "English":
			self.label_8.setText(unicode("Video Downloaded"))
			       
 		self.downVideoDescriptiont.clear()
		self.downVideoTitle.clear()
		self.downVideoViewCount.clear()
		
		       		
app = QtGui.QApplication(sys.argv)
app.setApplicationName("pindir")
window = MainWindow()
window.show()
sys.exit(app.exec_())